using System;
using System.Xml;
using System.IO;
using System.Collections;

namespace ECCIT.Configuration
{
	/// <summary>
	/// </summary>
	[Serializable]
	public class DirectoryManager : ConfigManager
	{
		private const string DirectoryNodeName	= "Directory";
		private const string DirectoryKey		= "key";
		private const string DirectoryValue		= "value";
	
		private Hashtable _directories;

		public Hashtable Directories
		{
			get{ return _directories; }	
		}

		/// <summary>
		///		The constructor without parameter is only designed for AjaxPro reflection
		/// </summary>
		public DirectoryManager(){}

		/// <summary>
		///		
		/// </summary>
		/// <param name="appRootDirectory">The root directory of the running application</param>
		public DirectoryManager(string appRootDirectory) : base(appRootDirectory, "Directory.config")
		{
			// Load Directory.config file to XmlDocument 
			XmlDocument configDoc = GetConfigDocument();
			InitializeDirectories(configDoc);
		}

		private void InitializeDirectories(XmlDocument configDoc)
		{
			_directories = new Hashtable();
			XmlNodeList dirNodes = configDoc.GetElementsByTagName(DirectoryNodeName);
			foreach( XmlNode dirNode in dirNodes )
			{
				string key = dirNode.Attributes.GetNamedItem(DirectoryKey).InnerText;
				string value = dirNode.Attributes.GetNamedItem(DirectoryValue).InnerText;
				_directories.Add(key, value); 	
			}			
		}
	}
}
